# -*- coding:utf-8 -*-
import datetime  
import time
from watchdog.observers import Observer  
from watchdog.events import FileSystemEventHandler
from PyQt5 import QtCore
import logging
class MyHandler(FileSystemEventHandler):  
    def __init__(self,w):
        self.w=w
        self.files=[]
    def on_created(self,event):
        logging.info([datetime.datetime.now(),"文件 %s 被创建" %(event.src_path)])
        f=event.src_path
        if f in self.files:
            pass
        else:
            self.files.append(f)
            self.w.created.emit(f)
class Watch(QtCore.QObject):
    created=QtCore.pyqtSignal(object)
    def __init__(self,path):
        super().__init__()
        event_handler = MyHandler(self)  
        self.observer = Observer()  
        self.path=path#r'\\10.0.114.230\化学分析室\仪器采集\caiji\ajl5110_back'
        self.observer.schedule(event_handler, path=path, recursive=False)  
        logging.info(["watch",self.path])
        try:
            self.observer.start()  
        except FileNotFoundError:
            pass

